const webpack = require('webpack')
const { merge } = require('webpack-merge');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

const OptimezeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')

const commonConfig = require('./webpack.config.common.js');
const handler = (percentage, message, ...args) => {
    // e.g. Output each progress message directly to the console:
    console.info(percentage, message, ...args);
};
const productionConfig = {
    mode: 'production',
    devtool: 'cheap-module-source-map',
    optimization: {
        minimize: true,

    },
    module: {
        rules: [{
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    "css-loader",
                    "postcss-loader"
                ]
            },
            {
                test: /\.scss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    {
                        loader: 'css-loader',
                        options: {
                            importLoaders: 2
                        }
                    },
                    'postcss-loader',
                    'sass-loader'
                ]
            }
        ]
    },
    plugins: [
        new MiniCssExtractPlugin(),
        new OptimezeCSSAssetsPlugin({}),
        new webpack.ProgressPlugin(handler)
    ]
};

module.exports = merge(productionConfig, commonConfig);